package com.qvtu.web.controller;


import com.qvtu.web.config.AjaxResult;
import com.qvtu.web.domain.BookCategroy;
import com.qvtu.web.domain.BookStatus;
import com.qvtu.web.domain.Books;
import com.qvtu.web.service.IBookCategroyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hyy
 * @since 2024-06-14
 */
@Controller
@RequestMapping("/bookCategroy")
public class BookCategroyController {

    @Autowired
    private IBookCategroyService bookCategroyService;

////    @RequestMapping("/")
//    public  String bookCategroy(Model model)
//    {
//        List categroyList =bookCategroyService.list();
//        model.addAttribute("categroyList",categroyList);
//        return  "MainInterface/bookCategroy";
//    }

    @RequestMapping("/save")
    public String bookCategroyAdd()
    {
        return "bookCategroy_chage";
    }

    @RequestMapping("/edit{id}")
    public String booksEdit(Model model,@PathVariable("id") Integer num){
        BookCategroy categroyList =bookCategroyService.getById(num);
        model.addAttribute("categroyList",categroyList);
        return "MainInterface/bookCategroyEdit";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public AjaxResult delete(Long id){
        bookCategroyService.removeById(id);
        System.out.println(AjaxResult.success());
        return AjaxResult.success();
    }
    @RequestMapping("/saveOrUpdata")
    @ResponseBody
    public AjaxResult update(BookCategroy book){
        if(book.getId() == null){
            book.setCreateTime(LocalDateTime.now());
            book.setUpdataTime(LocalDateTime.now());
        }else{
            book.setUpdataTime(LocalDateTime.now());
        }
        bookCategroyService.saveOrUpdate(book);
        return AjaxResult.success();
    }
}

